<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list1';
$tabs=array();
for($i=1;$i<=7;$i++){
	$day=date("Y-m-d",strtotime("+".$i." day"));
	$tabs[]=array('op'=>'list'.$i,'quary'=>'key='.$i,'key'=>$i,'title'=>$day.'备货');
}
$return['tabs']=$tabs;
if($_RQ['op']=='list'|| $_RQ['op']=='list1'|| $_RQ['op']=='list2'|| $_RQ['op']=='list3'|| $_RQ['op']=='list4'|| $_RQ['op']=='list5'|| $_RQ['op']=='list6'|| $_RQ['op']=='list7'|| $_RQ['op']=='list8'){
	$key=intval($_RQ['key'])?:1;
	$type=intval($_RQ['type'])?:1;
	$day=date("Y-m-d",strtotime("+".$key." day"));
	$return['params']['key']=$key;
	$return['params']['type']=$type;
	$params=array('day'=>$day,'sendtype'=>$type,'status'=>0,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']);
	$sendlogs=pdo_getall('jy_peiorder_sendlog',$params);
	$daygoods=array();
	$goodsnum=0;
	if($sendlogs){
		foreach($sendlogs as &$sv){
			$peisetgoods=json_decode($sv['goods'],true);
			foreach($peisetgoods as $k=>$gv){
				$goodsnum +=$gv['num'];
				$key=$gv['optionid']?$gv['goodsid'].'_'.$gv['optionid']:$gv['goodsid'];
				if($daygoods['goods'][$key]){
					$daygoods['goods'][$key]['info']=pdo_get('jy_weishop_goods',array('id'=>$gv['goodsid']),array('title','image','price','merchid'));
					$daygoods['goods'][$key]['num'] +=$gv['num'];
					$daygoods['goods'][$key]['lognum'] ++;
				}else{
					$gv['lognum']=1;
					$daygoods['goods'][$key]=$gv;
				}
			}
		}
	}
	$return['daylognum']=count($sendlogs);
	$return['goodsnum']=$goodsnum;
	$this->session('goodsnum',$goodsnum);
	$return['list']=array_values($daygoods['goods']);
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'info.image','title'=>'商品图片','type'=>'image'),
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'selespename','title'=>'商品规格','type'=>'string'),
			array('name'=>'num','title'=>'商品数量','type'=>'string'),
		),'batch'=>array(
			array('type'=>'modal','url'=>'look','title'=>'商品总数'.$goodsnum.'件'),
		),
		),
	);
	if($_SESSION['os']=='windows' || $_SESSION['os']=='window'){
		$return['htmls']=$htmls;
	}
	exi($return);
}
if($_RQ['op']=='look'){
	$item['goodsnum']=$this->session('goodsnum');
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'look',
		'desc'=>'商品总数',
		'look'=>array(
			array('name'=>'goodsnum','title'=>'商品总数','type'=>'string'),
		),
	);
	exi($return);
}